<?php
require_once('passwords.php');
function getConnection()
{
	$ret = mysql_connect("wyvern.cs.newpaltz.edu","plotkinm","FaceBooK");
	mysql_select_db("plotkinm_db",$ret);
	return $ret;
}

function AddUser($id, $app_id, $session_key)
{
	$conn = getConnection();
	$sql = 	"INSERT INTO Users (id, app_id, current, session_key, updated_at) VALUES ('$id', '$app_id', true, '$session_key', NOW())"
		. 	"ON DUPLICATE KEY UPDATE current=true, session_key='$session_key', updated_at=NOW()";
	mysql_query($sql, $conn);
	echo mysql_error($conn);
	mysql_close($conn);
}

function DeleteUser($id, $app_id)
{
	$conn = getConnection();
	$sql = "UPDATE Users Set current=false, updated_at=NOW() WHERE id='$id' and app_id='$app_id'";
	
	mysql_query($sql, $conn);
	echo $sql;
	echo mysql_error($conn);
	mysql_close($conn);
}
function print_debug($ob)
{
	global $debug;
	if(isset($debug) && $debug == true)
	{
		echo '<pre>';
		print_r($ob);
		echo '</pre>';
	}
}